import requests
from lxml import etree

page = 1
datas = []
while True:
    url = f"https://quotes.toscrape.com/page/{page}/"
    res = requests.get(url)
    tree = etree.HTML(res.text)
    items = tree.xpath("//div[@class='quote']")
    for item in items:
        content = item.xpath(".//span[@class='text']/text()")
        author = item.xpath(".//small[@class='author']/text()")
        tag = item.xpath("./div[@class='tags']/text()")
        datas.append({"content": content[1:-1], "author": author, "tags": tag})
    print(f"爬取{page}页结束")
    next_btn = tree.xpath('//li[@class="next"]')
    if next_btn:
        page += 1
    else:
        break
